# -*-coding:utf-8-*-
import copy
from functools import reduce
import operator

a = [1, 2, 3]
b = [5, 6, 7]

# 打包 [(1, 5), (2, 6), (3, 7)]
c = list(zip(a, b))

# 合并 [1, 2, 3, 5, 6, 7]
d = a + b

# 合并成元组 (1, 2, 3, 5, 6, 7), 合并成列表[*a, *b]
e = (*a, *b)

# 初始化
i_1 = [0] * 8
i_2 = list(i * 2 for i in range(10))  # 列表解析
i_3 = list(i * 2 for i in range(10) if i % 2 == 0)  # 增加if语句的列表解析
i_4 = list(j for i in range(2) for j in range(5))  # 多个for语句的列表解析,结果为[0,1,2,3,4,0,1,2,3,4]
i_5 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
i_6 = [i[0] for i in i_5]
for x, y, z in i_5:
    print('{},{},{}'.format(x, y, z))

# 排序
s_1 = [1, 2, 5, 4, 9, 6]
s_2 = [(1, 3), (5, 4), (8, 6), (7, 9)]
s_1.sort()
s_2.sort(key=lambda x: x[0], reverse=True)
print('排序后:{}'.format(s_1))
print('排序后:{}'.format(s_2))
s_3 = ['D', 'b', 'a']
s_3.sort(key=str.lower)
print('排序后:{}'.format(s_3))


# 拷贝
c_1 = [1, 2, 3]
c_2 = [c_1, 2, 3]
c_2.copy()  # 浅拷贝
copy.copy(c_2)  # 浅拷贝
c_3 = c_2[:]  # 浅拷贝
copy.deepcopy(c_2)  # 深拷贝